#pragma once
#include <iostream>
#include <string>
class calculator
{
private:
    int _x;
    int _y;
    char _op;
public:
    calculator(int x, char op, int y) : _x(x), _y(y), _op(op)
    {
    }
    calculator(){}
    std::string show()
    {
        std::string message = std::to_string(_x);
        message += _op;
        message += std::to_string(_y);
        message += "=?";
        return message;
    }
    double operator()()
    {
        return run();
    }
    int run()
    {
        int res = 0;
        switch (_op)
        {
        case '+':
            res = _x + _y;
            break;
        case '-':
            res = _x - _y;
            break;
        case '*':
            res = _x * _y;
            break;
        case '/':
            if(_y == 0)
            {
                std::cout << "除0错误" << std::endl;
                return 0;
            }
            res = _x / _y;
            break;
        default:
            std::cerr << "计算程序错误" << std::endl;
            return -1;
        }
        printf("计算结果为: %d %c %d = %d\n", _x, _op, _y, res);
        return res;
    }
};